package leetcode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class nine {
    public static int minSubArrayLen(int target, int[] nums) {
        if(nums==null||nums.length==0){
            return -1;
        }
        int sum=0;
        int left=0;
        int right=0;
        int len=0;
        List<Integer> list=new ArrayList<>();
        int ret= Arrays.stream(nums).sum();
        if(ret<target){
            return 0;
        }
        for(left=0,right=0;right<nums.length;right++){
            sum+=nums[right];
            while(sum>=target) {
                list.add(right - left + 1);
                sum -= nums[left];
                left++;
            }
        }
        return Collections.min(list);

    }

    public static void main(String[] args) {
        int[] array={5,1,3,5,10,7,4,9,2,8};
        int len = minSubArrayLen(15,array);
        System.out.println(len);

    }
}
